from flask import request
from SQLOperation.UserSQLOperation import UserSQLOperation
from SQLConfig import app


@app.route('/searchByUsername', methods=['Get', 'POST'])
def searchByUsername():  # put application's code here
    """
    搜索病人
    """
    username = request.json.get("username")
    user = UserSQLOperation.searchByUsername(username)
    if user is None:
        return "user not exist"
    else:
        # 解析数据，返回json格式
        return {
            "username": user.username
            , "password": user.password
            , "phone": user.phone
            , "email": user.email
            , "name": user.name
            , "gender": user.gender
            , "region": user.region
            , "introduction": user.introduction
        }
